package abc.dev.auth.model;

import abc.dev.auth.to.*;
import abc.annotation.Associative;
import java.util.List;
import abc.dev.auth.model.OnlineModel;
import abc.model.IEntity;
import abc.dev.auth.vo.OnlineVo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableLogic;
import org.apache.ibatis.javassist.bytecode.ByteArray;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.Date;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import abc.base.BaseModel;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.alibaba.excel.annotation.ExcelIgnore;
import lombok.experimental.Accessors;

/**
* <p>
* 在线账号
* </p>
*
* @author linlurui
*/
@Data
@Accessors(chain = false)
@Component
@TableName("online")
public class OnlineModel extends BaseModel<OnlineModel> implements IEntity<OnlineModel> {

    private static final long serialVersionUID = 1L;

    /**
    * 登录账号
    */
    @TableField("account")
    private String account;

    /**
    * 登录平台
    */
    @TableField("platform")
    private String platform;

    /**
    * 当前Token
    */
    @TableField("token")
    private String token;

    /**
    * 登录时间
    */
    @ExcelIgnore
    @TableField(value = "login_time", fill = FieldFill.INSERT)
    private Date loginTime;

    /**
    * 账号状态
    */
    @TableField("account_state")
    private Integer accountState;

    /**
    * 登录IP
    */
    @TableField("ip")
    private String ip;

    /**
    * 过期时间
    */
    @TableField("expir")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long expir;

    /**
    * 私钥
    */
    @TableField("private_key")
    private String privateKey;

    @ExcelIgnore
    @TableField(exist = false)
    @Associative(table="online_attr", foreignKey="online_id", type=OnlineAttrTo.class)
    private List<OnlineAttrTo> onlineAttrList;

    @Override
    public Serializable pkVal() {
        return null;
    }

    @Override
    public OnlineVo toVo() {
        OnlineVo entity = new OnlineVo();
        entity.setId(id);
        entity.setAccount(account);
        entity.setPlatform(platform);
        entity.setToken(token);
        entity.setLoginTime(loginTime);
        entity.setAccountState(accountState);
        entity.setIp(ip);
        entity.setExpir(expir);
        entity.setPrivateKey(privateKey);
        entity.setOnlineAttrList(onlineAttrList);
        return entity;
    }
}
